package com.example.springflowable.common;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * @Classname Resutls
 * @Description TODO
 * @Date 2022/5/6 16:02
 * @Created by XiongXiong
 * @Author: X.I.O
 */
public class Results {

    private static JSONObject getJSONObject(){
        return new JSONObject();
    }

    public static JSONObject success(){
        JSONObject object= getJSONObject();
        object.put(Contants.CODE,0);
        object.put(Contants.MSG,Contants.SUCCESS);
        return object;
    }

    public static JSONObject success(String msg){
        JSONObject object=success();
        object.put(Contants.MSG,msg);
        return object;
    }

    public static JSONObject success(Object data){
        JSONObject object=success();
        object.put(Contants.DATA,data);
        return object;
    }

    public static <T> JSONObject successPage(IPage<T> iPage){
        return success(iPage.getRecords(),iPage.getTotal());
    }

    public static JSONObject success(Object data,Object total){
        JSONObject object=success();
        object.put(Contants.DATA,data);
        object.put(Contants.TOTAL,total);
        return object;
    }

    public static JSONObject error(){
        JSONObject object= getJSONObject();
        object.put(Contants.CODE,1);
        object.put(Contants.MSG,Contants.ERROR);
        return object;
    }

    public static JSONObject error(Integer code,String msg){
        JSONObject object=error();
        object.put(Contants.CODE,code);
        object.put(Contants.MSG,msg);
        return object;
    }

    public static JSONObject error(String msg){
        JSONObject object=error();
        object.put(Contants.MSG,msg);
        return object;
    }
}
